package com.lengxf.pay.ali.config;

import cn.hutool.core.util.StrUtil;
import com.alipay.api.AlipayConfig;
import com.lengxf.pay.common.config.BasePayConfig;
import com.lengxf.pay.common.config.ServerAddr;
import com.lengxf.pay.common.enums.PayChannel;
import lombok.Data;
import lombok.EqualsAndHashCode;


@Data
@EqualsAndHashCode(callSuper = true)
public class ALI_PayConfig extends BasePayConfig {


    //appId 商户应用id
    private String appId;

    //商户收款账号
    private String sellerId;


    public AlipayConfig convertToAlipayConfig() {
        AlipayConfig alipayConfig = new AlipayConfig();
        String aliAddr = ServerAddr.getAddr(PayChannel.ALI);
        if (StrUtil.isNotBlank(aliAddr)) {
            alipayConfig.setServerUrl(aliAddr);
        }
        alipayConfig.setPrivateKey(keyPrivate());
        alipayConfig.setAlipayPublicKey(keyPublic());
        alipayConfig.setFormat("json");
        alipayConfig.setCharset("UTF-8");
        alipayConfig.setSignType("RSA2");
        alipayConfig.setAppId(this.appId);
        return alipayConfig;
    }

}
